///静态帮助类
pub mod util;
pub mod queue;
///命令行模块
pub use clap;
///透传暴露的lib
pub use chrono;
pub use ignore;
pub use yaml_rust;
///日志模块
pub use fern;
pub use log;

///functions
pub fn lazy_initlogger(v: Option<log::LevelFilter>) -> Result<(), log::SetLoggerError> {
    let ret = fern::Dispatch::new()
        .format(|out, message, record| {
            out.finish(format_args!(
                "[{}]{}: {}",
                chrono::Local::now().format("[%H:%M:%S]"),
                record.level(),
                message
            ))
        })
        .level(v.unwrap_or(log::LevelFilter::Debug))
        .chain(std::io::stdout())
        .apply();
    ret
}

#[test]
fn test_libs() {
    use crate::util::filesys::zip_dir;
    use crate::Log;
    use ignore::{DirEntry, Error, WalkBuilder};
    use log::{debug, info};
    use std::path::Path;
    use std::{env, fs};

    fn ignore_zipfile() -> Result<(), Error> {
        let cur = env::current_dir()?;
        let src_dir = cur.join("test");
        let tar_f = src_dir.join("out.zip");
        println!("cur path {:?}", src_dir);
        let zipfile = std::fs::File::create(&tar_f).unwrap();
        let mut ws2 = WalkBuilder::new(&src_dir);
        let ret = &mut ws2.build().into_iter().filter_map(|v| {
            println!("find file->{:?}", v.clone().unwrap().path().display());
            return v.ok();
        });
        let zip_f = zip_dir(ret, src_dir.to_str().unwrap(), zipfile);
        if zip_f.is_err() {
            fs::remove_file(&tar_f.as_path());
        }
        Ok(())
    }
}
